package com.tutor.lzm.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.tutor.lzm.R;
import com.tutor.lzm.bean.SubjectBean;
import com.tutor.lzm.function.teacher.act.TeacherListAct;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zzgpc on 2017-8-24.
 * 单行滑动科目adapter
 */
public class SingleCourseAdapter extends RecyclerView.Adapter<SpeedHourHolder> {
    private Context mContext = null;
    List<SubjectBean> subjectList;
    private LayoutInflater mInflater;

    public SingleCourseAdapter(Context context, List<SubjectBean> subjectList) {
        this.mContext = context;
        this.subjectList = subjectList;
        this.mInflater = LayoutInflater.from(context);

    }

    @Override
    public SpeedHourHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_course_icon, parent, false);

        SpeedHourHolder holder = new SpeedHourHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SpeedHourHolder holder, final int position) {
        final SubjectBean subjectBean = subjectList.get(position);
        Picasso.with(mContext)
                .load(subjectBean.getCategoryImgUrl())
                .into(holder.speedImage);
        holder.speedImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TeacherListAct.start(mContext, subjectBean.getCategoryName(), subjectBean.getCategoryId());
            }
        });

    }

    @Override
    public int getItemCount() {
        return subjectList.size();
    }


}

class SpeedHourHolder extends RecyclerView.ViewHolder {
    @BindView(R.id.image)
    ImageView speedImage;

    public SpeedHourHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);
        itemView.setTag(this);
    }
}